//
// Created by JYL on 2024-08-06.
//

#include "KeyLed.h"


uint8_t Trg,Cont;
uint8_t key_times,key_temp;

uint8_t KEY_Scan(void)
{
    KEY key = KEY_None;
    uint8_t ReadData = (KEY_PORT)^0xff;
    Trg = ReadData & (ReadData ^ Cont);
    Cont = ReadData;
    if(Trg)key_temp=Trg;
    if(Cont && ++key_times>=100)key_times=100;
    if(!Trg && !Cont && key_temp){
        if(key_times>=25){
            if(key_temp==0x01)key = KEY1_Long;
            if(key_temp==0x02)key = KEY2_Long;
            if(key_temp==0x04)key = KEY3_Long;
            if(key_temp==0x08)key = KEY4_Long;
        }else{
            if(key_temp==0x01)key = KEY1_Short;
            if(key_temp==0x02)key = KEY2_Short;
            if(key_temp==0x04)key = KEY3_Short;
            if(key_temp==0x08)key = KEY4_Short;
        }
        key_times = key_temp=0;
    }
    return key;
}






